<template>
	<view>
		<view class="padding-sm bg-white flex solid-top">
			<view>
				<image :src=" image+coachUserInfo.img" mode="" style="height: 150rpx;width:200rpx;" class="bg-gray"></image>
			</view>
			<view class="margin-left">
				<view>{{coachUserInfo.name}}</view>
				<view class="margin-tb-sm">驾龄 {{coachUserInfo.card_year}}年</view>
				<view class="flex">
					<view v-for="(item,index) in starLength">
						<image src="../../static/1xing.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
					</view>
					<view class="text-sm margin-left-sm">
						{{coachUserInfo.star}}分
					</view>
				</view>
			</view>
		</view>
		<view class="bg-white margin-top padding">
			<view class="flex">
				技术水平：
				<view v-for="(item,index) in starList" @click="starMen(index,item)">
					<view>
						<image :src="item.isStar?'/static/3xing.png':'/static/1xing.png' " mode="" style="width: 30rpx;height: 30rpx;"></image>
					</view>
				</view>
			</view>
			<view class="rows margin-top">
				<view class="margin-right-sm">
					内容
				</view>
				<view>
					<textarea value="" placeholder="请输入" class="border" style="height: 200rpx;" v-model="content" />
					</view>
			</view>
		</view>
		<view class="bg-white text-center margin-top padding-sm margin radius" @click="evaluate">
			提交
		</view>
	</view>
</template>

<script>
	const app = getApp().globalData
	import {coachUser,evaluate} from '../../common/path.js'
	export default {
		data(){
			return{
				pid:'',
				detailID:'',
				coachUserInfo:{},
				image:'',
				content:'',
				starList:[
					{
						isStar:true
					},
					{
						isStar:true
					},
						{
						isStar:true
					},
					{
						isStar:true
					},
					{
						isStar:true
					}
				],
				starData:0,
				starLength:3
			}
		},
		onLoad(option) {
			this.image = app.image
			this.pid = option.pid
			this.detailID = option.id
			console.log(option)
			this.coachUser()
		},
		methods:{
			//选择了几个星
			starMen(index,item){
				let arrSelect = this.starList;
				arrSelect.forEach(oneone => {
					oneone.isStar = true;
				})
				for(let i=0; i<index+1; i++) {
					arrSelect[i].isStar = false
				}
				this.starList = arrSelect
				console.log(index+1)
				this.starData = index+1
			},
			coachUser(){
				let data = {
					id:this.pid
				}
				this.$axios.axios('POST',coachUser,data)
				.then(res=>{
					console.log('获取到的教练信息',res);
					if(res.status ==1){
						this.coachUserInfo = res.data
						console.log( '当前多少颗星',Number(res.data.star.split(".")[0]))
						this.starLength = Number(res.data.star.split(".")[0])
					}
				})
				.catch(err=>{
					console.log(err);
				})
			},
			evaluate(){
				let data = {
					id:this.detailID,
					uid:app.userInfo.id,
					fid:this.pid,
					content:this.content,
					star:this.starData, //星级
				}
				this.$axios.axios("POST",evaluate,data)
				.then(res=>{
					console.log(res)
					if(res.staus == 1){
						this.$tools.showToast(res.msg)
					}else{
						this.$tools.showToast(res.msg)
					}
				})
				.catch(er=>{
					this.$tools.showToast("网络异常",er)
				})
			}
		}
	}
</script>

<style>
	

</style>
